import type { tabber } from "@/types/common"
import { defineStore } from "pinia"
import { ref } from "vue"

/*
 +----------------------------------------------------------------------
 + Title        : tabber pinia 存储
 + Author       : huwl
 + Version      : 1.0.0
 + Initial-Time : 2024-12-24
 + Last-time    : 这个文件最后修改的时间 + 修改人的名称
 + Desc         : 底部导航 pinia 存储
 +----------------------------------------------------------------------
*/
export const useTabberStore = defineStore('tabber', () => {

    // 定义导航列表
    const tabberList = ref<tabber[]>([
        {
            name: '首页',
            icon: 'icon-shouye',
            url: '/pages/tabber_demo/index',
            badge: 0,
            dot: false
        },
        {
            name: '放映厅',
            icon: 'icon-shouye',
            url: '/pages/review/index',
            badge: 0,
            dot: false
        },
        {
            name: '直播主线程',
            icon: 'icon-shouye',
            url: '/pages/sinatv/index',
            badge: 0,
            dot: false
        },
        {
            name: '大法师的',
            icon: 'icon-shouye',
            url: '/pages/review/index',
            badge: 0,
            dot: false
        }
    ])

    /**
     * 编辑导航
     * 
     * @param number index
     * @param tabber data
     * @returns void
     * @author huwl
     */
    const editTabber = (index: number, data: tabber) => {
        const tabber = tabberList.value[index]
        for (const key in data) {
            tabber[key as never] = data[key as never]
        }
    }

    return {
        tabberList,

        editTabber
    }
},
// 持久化
{
    persist: {
        storage: {
            getItem(key: any) {
                return uni.getStorageSync(key)
            },
            setItem(key: any, value: any) {
                uni.setStorageSync(key, value)
            },
        }
    }
})